package main;

import com.csvreader.CsvReader;
import entity.Bill;
import entity.Vo;
//import thetransformOfStringandPojo.Test;

import java.beans.PropertyDescriptor;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.ArrayList;

public class testTry {

    public static Object invokeMethodBill(String[] arr) throws Exception {
        Object obj = Bill.class.newInstance();//创建对象实例
        Field[] fields = Bill.class.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            Field f = fields[i];
            //使用java.beans.PropertyDescriptor获取Method
            PropertyDescriptor pd = new PropertyDescriptor(f.getName(), Bill.class);
            Method m = pd.getWriteMethod();//获取对象的写入方法
            m.invoke(obj, arr[i]);
        }
        return obj;

    }

    public static void main(String[] args) {
        try {
            ArrayList<String[]> bill=new ArrayList<>();

            String billPath="C:\\Users\\dinstar\\Desktop\\bill2.csv";

            CsvReader csvReader=new CsvReader(billPath,',', Charset.forName("UTF-8"));

            while (csvReader.readRecord()){
                bill.add(csvReader.getValues());
            }
            csvReader.close();

            String[] tempArr=bill.get(1);

            Bill temp=new Bill();


            temp=(Bill)invokeMethodBill(tempArr);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
